package com.walle.concurrenttest.pattern.threadspecificstorage;

/**
 * @author zhangjiapeng
 * @Package com.walle.concurrenttest.pattern.threadspecificstorage
 * @Description: ${todo}
 * @date 2019/2/27 13:54
 */
public class Log {

    private static final ThreadLocal<TsLog> TS_LOG_THREAD_LOCAL = new ThreadLocal<>();

    public static void print(String s){
        getTSLog().write(s);
    }

    public static void close(){
        getTSLog().close();
    }

    private static TsLog getTSLog(){
        TsLog tsLog = TS_LOG_THREAD_LOCAL.get();

        if(tsLog == null){
            tsLog = new TsLog(Thread.currentThread().getName() + "-log.txt");
            TS_LOG_THREAD_LOCAL.set(tsLog);
        }
        return tsLog;
    }


}
